package org.spring.springboot.service.join;

import org.apache.commons.lang3.StringUtils;
import org.spring.springboot.base.BaseCommon;
import org.spring.springboot.dao.join.TsFastJoinInfoMapper;
import org.spring.springboot.domain.join.TsFastJoinInfo;
import org.spring.springboot.domain.join.TsFastJoinInfoExample;
import org.spring.springboot.domain.join.TsFastJoinInfoKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhaobo
 * @version 1.0
 * @date 2019/6/15 17:04
 */
@Service
public class TsFastJoinInfoService extends BaseCommon {

    @Autowired
    private TsFastJoinInfoMapper tsFastJoinInfoMapper;

    public TsFastJoinInfo queryByKey(TsFastJoinInfoKey key){
       return tsFastJoinInfoMapper.selectByPrimaryKey(key);
    }

    public Integer insert(TsFastJoinInfo info){
        return tsFastJoinInfoMapper.insert(info);
    }

    public Integer update(TsFastJoinInfo info){
        return tsFastJoinInfoMapper.updateByPrimaryKey(info);
    }

    public Integer delete(TsFastJoinInfo info){
     return tsFastJoinInfoMapper.deleteByPrimaryKey(info);
    }

    public Map<String,Object> selectForPage(String offset,String limit, String startTime,String endTime,String joinName,String joinPhone){
        TsFastJoinInfoExample ex = new TsFastJoinInfoExample();
        ex.setOffset(getIntVal(offset));
        ex.setLimit(getIntVal(limit));
        TsFastJoinInfoExample.Criteria criteria = ex.createCriteria();
        if(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)){
            criteria.andJoinCreateTimeBetween(startTime,endTime);
        }
        if(StringUtils.isNotBlank(joinName)){
            criteria.andJoinNameLike(joinName);
        }
        if(StringUtils.isNotBlank(joinPhone)){
            criteria.andJoinPhoneLike(joinPhone);
        }
        ex.setOrderByClause(" join_create_time asc ");
        Integer total = tsFastJoinInfoMapper.selectCountByExample(ex);
        List<Map<String,Object>> list =tsFastJoinInfoMapper.selectByExample(ex);
        Map<String,Object> resMap = new HashMap<>(2);
        resMap.put("total",total);
        resMap.put("list",list);
        return resMap;
    }

    public Integer updateAuditByKey(String joinPhone,String joinCreateTime,String joinAuditRemark, Timestamp joinAuditTime,String joinAuditFlag){
//       return tsFastJoinInfoMapper.updateAuditByKey( joinPhone, joinCreateTime, joinAuditRemark, joinAuditTime, joinAuditFlag);
        Map<String,Object> map = new HashMap<>();
        map.put("joinPhone",joinPhone);
        map.put("joinCreateTime",joinCreateTime);
        map.put("joinAuditRemark",joinAuditRemark);
        map.put("joinAuditTime",joinAuditTime);
        map.put("joinAuditFlag",joinAuditFlag);
        return tsFastJoinInfoMapper.updateAuditByKey(map);
    }


}
